-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gitsunmin] Week 09 Solutions #527
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 풀이 감사합니다. 다음 주도 파이팅.
let right = nums.length - 1; | ||
|
||
while (left < right) { | ||
const mid = Math.floor((left + right) / 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굳이 floor은 안사용하셔도 괜찮을 것 같습니다. 이분탐색에서 while문에 등호를 넣거나 if나 else에서 등호를 넣거나 테스트 해보시면 좋을 것 같습니다.
function hasCycle(head: ListNode | null): boolean { | ||
if (!head || !head.next) { | ||
return false; | ||
} | ||
|
||
let slow: ListNode | null = head; | ||
let fast: ListNode | null = head.next; | ||
|
||
while (slow !== fast) { | ||
if (!fast || !fast.next) return false; | ||
slow = slow!.next; | ||
fast = fast.next.next; | ||
} | ||
|
||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 리뷰를 하면서 드는 생각인데 union-find로도 풀어볼 걸 그랬네요
const directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]; | ||
|
||
function dfs(r: number, c: number, visited: boolean[][], prevHeight: number) { | ||
if (r < 0 || c < 0 || r >= m || c >= n || visited[r][c] || heights[r][c] < prevHeight) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 귀찮아서 한 줄로 쓰기는 하는데, 리뷰어의 입장에서 코드 스멜이나 단축 평가를 고려하면 적절한 조건들로 나누는 게 좋을 것 같습니다. 이 경우는 index error가 일어나지 않을 r, c를 한정하기 위해 순서가 어쩔 수 없지만...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lymchgmk
이야기 감사합니다! 코드 스멜도 신경써볼게요!
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.